<include file="Public:header" />

<script type="text/javascript" charset="utf-8" src="/Public/ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="/Public/ueditor/ueditor.all.min.js"> </script>


<script type="text/javascript">

	window.UEDITOR_CONFIG.savePath=[ "topic/"];
	
    //实例化编辑器
	UE.getEditor('context');
</script>

<div>
	<a href="/admin.php?m=Admin&c=Index&a=topic&do=add">添加</a> &nbsp;&nbsp;搜索：<input name="search" id="searchInput"  />
</div>
<div class="article">
<if condition="$data['do'] eq 'add'">
<h2><if condition="$data['info']['id']">编辑<else />添加</if></h2>
 
<form method="post" id="topicForm" action="/admin.php?m=Admin&c=Index&a=topic&do=save">
<table width="100%" border="0">
  <tr>
    <td width="5%">标题</td>
    <td width="95%"><input name="name" type="text" id="name" value="{$data['info']['name']}" size="60" /></td>
  </tr>
  <tr>
    <td>url</td>
    <td><input name="url" type="text" id="url" value="{$data['info']['url']}" size="60" /></td>
  </tr>
  <tr>
    <td>标签</td>
    <td><input name="keyword" type="text" id="keyword" value="{$data['info']['keyword']}" size="60" /></td>
  </tr>
  <tr>
    <td>封面</td>
    <td>
		<div class="tupian" onclick="$('.uploadBtn').click();" style="cursor:pointer; width:100px; margin:5px; height:100px; background:#ccc;"><if condition="$data['info']['thumb']"><img src="{$data['info']['thumb200']}" style="max-width:100px; max-height:100px;" border=0 /><else />点击上传</if></div>    </td>
  </tr>
  <tr>
    <td valign="top">内容</td>
    <td><textarea name="context" id="context" style="width:90%; height:500px;">{$data['info']['context']}</textarea></td>
  </tr>
  <tr>
    <td height="99">&nbsp;</td>
    <td valign="top"><input type="submit" name="button" id="button" value="提交" style="padding:5px;" />
      <a href="javascript:" onclick="if(confirm('确定返回列表吗？内容可能会丢失')){ location.href='/admin.php?m=Admin&c=Index&a=topic'} return">返回</a>
      <input name="id" type="hidden" id="id" value="{$data['info']['id']}" />
      <input type="hidden" name="thumb" value="{$data['info']['thumb']}" />    </td>
  </tr>
</table>
</form>
<form method="post" class="uploadImageForm" enctype="multipart/form-data" class="hide" target="iframe-form" action="/?c=Upload&a=upload">
<input type="file" name="upload" class="uploadBtn hide"  />
<input type="hidden" name="dir" id="topicdir" value="topic/" />
</form>
<else />
<h2>专题列表</h2>

<table width="100%" border="1" cellpadding="5" cellspacing="0">
  <tr>
    <th width="1055">标题</th>
    <th width="237">链接</th>
    <th width="180">最后修改时间</th>
    <th width="100">操作</th>
  </tr>
  <volist name="data['topic']['list']" id="val">
  <tr>
    <td>{$val['name']}</td>
    <td>{$val['url']}</td>
    <td title="发表时间：{$val['createtime']}">{$val['updatetime']}</td>
    <td><a href="/admin.php?m=Admin&c=Index&a=topic&do=add&id={$val['id']}">编辑</a>&nbsp;<a href="/admin.php?m=Admin&c=Index&a=topic&do=delete&id={$val['id']}" onclick="return confirm('确定删除吗?')">删除</a></td>
  </tr>
  </volist>
</table>
<p><if condition="$_GET['p'] gt 1"><a href="/admin.php?m=Admin&c=Index&a=topic">首页</a>&nbsp;&nbsp;<a href="/admin.php?m=Admin&c=Index&a=topic&p={$data['article']['next_page']-1}">上一页</a>&nbsp;&nbsp;<else /></if> <if condition="$data['article']['next_page']"><a href="/admin.php?m=Admin&c=Index&a=topic&p={$data['article']['next_page']}">下一页</a>&nbsp;&nbsp;</if></p>
</if>
</div>
<script>
$(document).ready(function(){	
	$('.uploadBtn').on('change',function(){
		var editForm = $('.uploadImageForm');
		//$.jBox.tip('Loading...','loading');
		//editForm.find('.tupian').html('上传中...');
		$('.uploadImageForm').submit();
	});
	$('#topicForm').submit(function(){
		
	});
	$('#url').blur(function(){
		var url = $(this).val();
		if(!/^[a-z]{3,20}$/.test(url)){
			alert('url必须为3~20个小写字母');
			return false;
		}
	});
	$(this).mouseover(function(){
		var url = $('#url').val();
		$('#topicdir').val('topic/'+url);
		window.UEDITOR_CONFIG.savePath=[ "topic/"+url];
	});
});
//上传成功回调
function uploadCallBack(domain,path){
	var editForm = $('#topicForm');
	editForm.find('[name=thumb]').val(path);
	editForm.find('.tupian').html('<img src="'+domain+path+'" style="max-width:100px; max-height:100px;" border=0 />');
	$.jBox.tip('上传成功','success');
}
</script>
<iframe id="iframe-form" name="iframe-form" src="" class="hide" ></iframe>
<include file="Public:footer" />
